
import { GameplayComponent } from "../GameplayComponent";
import { Sglt } from "../m/SgltDefine";
import { CommonSystem } from "../m/systems/CommonSystem";
import GpPathGridNode from "./GpPathGridNode";

import { _decorator, Component, instantiate, Layout, Node, Prefab, Size, UITransform } from 'cc';
const { ccclass, property } = _decorator;


@ccclass
export default class GpPathGrid extends GameplayComponent {

    @property(Prefab)
    gridNodePrefab: Prefab = null;


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    onInit(): void {
        const ecsWorld = this.prop.ecsWorld
        const commonSystem = ecsWorld.system(CommonSystem)
        const worldInfo = ecsWorld.getSingleton(Sglt.WorldInfo)
        const gridNodePrefab = this.gridNodePrefab
        this.node.getComponent(Layout).cellSize =new Size(worldInfo.pfNodeWidth, worldInfo.pfNodeWidth)
        this.node.getComponent(UITransform).setContentSize(worldInfo.width, worldInfo.height)
        for (let y = 0; y < worldInfo.pfGridWidth; y++) {
            for (let x = 0; x < worldInfo.pfGridHeight; x++) {
                // const node = instantiate(gridNodePrefab)
                // node.getComponent(UITransform).setContentSize(worldInfo.pfNodeWidth, worldInfo.pfNodeWidth)
                // node.getComponent(GpPathGridNode).x = x
                // node.getComponent(GpPathGridNode).y = y
                // node.getComponent(GpPathGridNode).grid = commonSystem.grid
                // this.node.addChild(node)
            }
        }
    }

    start() {

    }

    // update (dt) {}
}
